#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int find_postfix(char *str, char *postfix){
    int len_str = strlen(str);
    int len_pfx = strlen(postfix);
    
    if( len_pfx > len_str ){
        printf("[warning] %s:%s:L:%d --> len_pfx > len_str!\n",
                __FILE__, __func__, __LINE__);
        return -1;
    } else {
        char *tmp = (char*)malloc(sizeof(char)*len_pfx);
        int i;
        for(i=0; i<len_pfx; i++){
            tmp[i] = str[len_str-len_pfx+i];
        }
        
        printf("tmp = %s\n", tmp);
        
        if( strcmp(postfix, tmp) == 0 ){
            printf("found postfix(%s) in string(%s)\n",postfix,str);
        }
        
        return 0;
    }
}

int main( int argc, char *argv[] ){

/*    
    char bfile[1024] = "";
    char tmp[512] = "";
    
    int len_bfile = strlen(bfile);
    int len_tmp = strlen(tmp);
    
    printf("len_bfile   = %d\n", len_bfile);
    printf("len_tmp     = %d\n", len_tmp);
    
    sprintf(tmp, "%s", argv[1]);
    
    len_tmp = strlen(tmp);  
    printf("len_tmp     = %d\n", len_tmp);
*/

    if( argc != 3 ){
        printf("usage:\n\t%s string postfix\n", argv[0]);
        return 0;
    }
    
    find_postfix(argv[1],argv[2]);
  
    return 0;
}
